package net.jarang.study.spring;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcConnection {
	private static final String driver = "org.gjt.mm.mysql.Driver";
	private static final String url = "jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=euc-kr";
	private static final String user = ""; 
	private static final String pwd = "";

	public static void main(String[] args) {
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;

		try {
			Class.forName(driver);// DB driver�� �ε��Ŵ

			// db�� ����....
			conn = DriverManager.getConnection(url, user, pwd);

			conn.setAutoCommit(false);

			// ������ db�� query���� �������� statement����
			stmt = conn.createStatement();

			// ���� query���� db���� �����ϰ� ��
			String query = "SELECT * FROM editxml";
			rs = stmt.executeQuery(query);

			// executeUpdate()���....insert, delete,update � ���
			while (rs.next()) {
				System.out.println(rs.getString(1) + " " + rs.getInt(2) + " "
						+ rs.getFloat(3) + " " + rs.getFloat(4) + " "
						+ rs.getString(5));
				// �� type�� �°� �о�´�.(num)�� field ��ȣ...
			}
			conn.commit();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e1) {
			// executeQuery���� next()�� throws �ϴ� exception!!!
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			e1.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (stmt != null) {
				try {
					stmt.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (conn != null) {
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	
	public void insert() {
		//connection �������� �κ�
		//Ʈ����� ���� �κ�
		
		//���� ����
		//��� ó��
		
		//�ڿ� �ʱ�ȭ
	}
}
